package com.liy.framework.common.web.context;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;


@Component
public class ApplicationContextProvider implements ApplicationContextAware
 {
     private static ApplicationContext context;

    public static ApplicationContext getApplicationContext() {
        return context;
    }


    public void setApplicationContext(ApplicationContext ac) throws BeansException {
        context = ac;
    }


    public static <T> T getBean(Class<T> tClass) {
        return (T) context.getBean(tClass);
    }

    public static <T> T getBean(String name, Class<T> tClass) {
        return (T) context.getBean(name, tClass);
    }

}


